﻿#include "ssShaderUnifor.h"


namespace StarSeeker
{

ssShaderUniform::ssShaderUniform()
{
	m_type = 0;
	m_glslID = -1;
}

void ssShaderUniform::Use(ssShader* pShader, const void* data, u32 count, u32 arrCount)
{
	//if (m_glslID==-1) //获取序号
	//{
		m_glslID = pShader->GetUniformLocation(m_glslName.GetString());
	//}
	if (m_glslID >= 0) //传递数据到显存
	{
		switch (m_type)
		{
		case SS_GL_UNIFORM_FLOAT:
			pShader->SetUniformFloat(m_glslID, (ssfloat*)data, count);
			break;
		case SS_GL_UNIFORM_VEC:
			pShader->SetUniformVector(m_glslID, (ssfloat*)data, arrCount, count);
			break;
		case SS_GL_UNIFORM_MAT:
			pShader->SetUniformMatrix(m_glslID, (ssfloat*)data, arrCount, count);
			break;
		case SS_GL_UNIFORM_TEX2D:
			pShader->SetUniformTextureLayer(m_glslID, count);
			break;
		case SS_GL_UNIFORM_INT:
			pShader->SetUniformInt(m_glslID, (i32*)data, count);
			break;
		default:
			break;
		}
	}
}

void ssShaderUniform::BindData( i32 type, const char* name)
{
	m_type = type;
	m_glslName = name;
}

}
